package com.icbc.open.chengdu.demo.account.openclose;


import com.csii.pp.icbc.util.MD5Util;
import com.csii.pp.icbc.util.Util;
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.api.request.SettlementAccountCloseacceptRequestV1;
import com.icbc.api.request.SettlementAccountCloseacceptRequestV1.SettlementAccountCloseAcceptRequestV1Biz;
import com.icbc.api.response.SettlementAccountCloseacceptResponseV1;
import com.icbc.open.chengdu.demo.BaseData;
import com.icbc.open.chengdu.demo.utils.SaveFileUtils;
import com.icbc.open.chengdu.demo.utils.GenerateKeyUtils;
import com.icbc.open.chengdu.demo.utils.SecretUtils;

/**
 * 结算账户销户
 * <p>
 * 工行在受理销户申请后的T+1日凌晨进行销户操作，客户需要在T+1日凌晨前将工行电子账户资产转走
 * <p>
 * 合作方通过API接口对我行个人II、III 类结算账户提出销户申请，我行进行销户前的相关信息检查，并根据事前双方约定，按需向客户发送短信验证码。
 *
 * @author xcz
 */
public class SettlementAccountCloseacceptTest {

    public static void main(String[] args) throws Exception {
        String sm4Key = GenerateKeyUtils.generateSM4Key(); //生成SM4密钥
        DefaultIcbcClient client = new DefaultIcbcClient(BaseData.APP_ID, BaseData.MY_RSA_PRIVATE_KEY, BaseData.ICBC_RSA_PUBLIC_KEY);
        SettlementAccountCloseacceptRequestV1 request = new SettlementAccountCloseacceptRequestV1();
        SettlementAccountCloseAcceptRequestV1Biz bizContent = new SettlementAccountCloseAcceptRequestV1Biz();
        request.setServiceUrl(BaseData.ACCOUNT_CLOSEACCEPT_URL);//API地址
        bizContent.setCorpNo(BaseData.APP_ID); //合作方机构编号
        bizContent.setTrxAccDate(BaseData.TEST_TRX_ACC_DATE); //合作方交易日期
        bizContent.setTrxAccTime(BaseData.TEST_TRX_ACC_TIME); //合作方交易时间
        bizContent.setCorpDate(BaseData.TEST_CORP_DATE); //合作方工作日期
        String corpSerNo = Util.getNonceStr(16);
        SaveFileUtils.setOpenAccount(corpSerNo);//保存单号，短信验证/订单查询时使用
        bizContent.setCorpSerno(corpSerNo); //合作方交易单号
        bizContent.setOutServiceCode("closeaccaccept");
        bizContent.setMediumId(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_ACCOUNT_NUMBER_2));
        bizContent.setSecretKey(SecretUtils.encryptSM2(sm4Key));
        bizContent.setMediumIdHash(MD5Util.string2MD5(BaseData.TEST_ACCOUNT_NUMBER_2));
        request.setBizContent(bizContent);
        SettlementAccountCloseacceptResponseV1 response = client.execute(request);
        System.out.println(JSON.toJSONString(response));
        if (response.isSuccess()) {
            SaveFileUtils.setSmsSendNo(response.getSmsSendNo());//保存短信验证码编号
        } else {
        }

    }
}
